#ifndef ENTITYQUADTREE_H
#define ENTITYQUADTREE_H

#include "QuadTree.h"
#include "Entity.h"
#include <vector>




#define MAXIMUM_ENTITIES_PER_NODE 1

class EntityQuadTree : public QuadTree{
public:
    unsigned int entityCount;
    static EntityQuadTree root;
    std::vector <Entity*> entities;	//collection of all entities in this node

	static std::list<Entity*> updateQueue;	//list of all entities which require update in the entire quadtree
	bool changed;

public:
    EntityQuadTree();
    ~EntityQuadTree();

    void UpdateNode();   //scan nodes for entities and unite/subdivide as necessary
    void AddEntity(Entity* entity);	//create a new entity and push it to the quad tree
    
    int GetEntityCountInNode();
    void PushEntityToCollection(Entity* entity);
    Entity* GetEntityAtNode(unsigned int i);
    EntityQuadTree* EntityQuadTree::GetNodeAtPoint(unsigned int x, unsigned int y);
    EntityQuadTree* GetNodeSurroundingRectangle(Rectangle* rect);
    static void InitializeRoot();
    void DivideLeafNode();
    void BlitQuadTree(unsigned int level = 0);
    void Clear();
    void TrimNodes();
	void PerformEntityCollisionSweep(Entity* entity);
	bool BranchesAreEmpty();
	void SetChanged(bool changed);	
	bool HasChanged();	
	void AddPendingEntities();
	void UniteLeafNodes();
};
#endif